"""
  模块描述：接收短信模块报告的服务端-示例
  @author 8522
  @date 2022-05-13 15:04:01
  版权所有 Copyright www.dahantc.com
"""
import json

from flask import Flask, request
import smsReceiveEntity

app = Flask(__name__)


# 接收上行回复短信报告
@app.route('/deliverReceive', methods=['POST'])
def deliverReceive():
    status = 'success'
    try:
        report = request.form.get('deliver')
        smsDeliverParam = smsReceiveEntity.SmsDeliverParam.parseObj(json.loads(report))
        print('收到上行回复短信报告：', str(smsDeliverParam.parseDict()))
    except Exception as e:
        print('数据解析异常 %s' % e)
        status = 'fail'
    return {'status': status}


# 接收短信下发状态报告
@app.route('/reportReceive', methods=['POST'])
def reportReceive():
    status = 'success'
    try:
        report = request.form.get('report')
        smsReportParam = smsReceiveEntity.SmsReportParam.parseObj(json.loads(report))
        print('收到短信下发状态报告：', str(smsReportParam.parseDict()))
    except Exception as e:
        print('数据解析异常 %s' % e)
        status = 'fail'
    return {'status': status}


if __name__ == '__main__':
    app.run(debug=False, port=8080)
